package com.asset.dispoal.user.service.commom;

import com.asset.dispoal.user.domain.db.mapper.SysUserMapper;
import com.asset.dispoal.user.dto.BsCourtInfo;
import com.asset.dispoal.user.dto.BsLawyerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;

import java.util.List;

/**
 * @author qr
 * @date 2022/5/12$
 */
@Component
public class QueryLawyerDetailCommand implements BaseCommand<String, Result> {

    @Autowired
    SysUserMapper sysUserMapper;

    @Override
    public Result<BsLawyerResponse> execute(String userId) {
        BsLawyerResponse bsLawyerResponse = sysUserMapper.queryLawyerDetail(userId);
        List<BsCourtInfo> courtList = sysUserMapper.queryCourtByUserId(userId);
        List<String> roleIdList = sysUserMapper.queryRoleByUserId(userId);
        List<String> depIdList = sysUserMapper.queryDepartmentByUserId(userId);
        if (!CollectionUtils.isEmpty(depIdList)) {
            bsLawyerResponse.setDepIds(depIdList);
        }
        if (!CollectionUtils.isEmpty(roleIdList)) {
            bsLawyerResponse.setRoleIds(roleIdList);
        }
        if (!CollectionUtils.isEmpty(courtList)) {
            bsLawyerResponse.setCourtList(courtList);
        }
        return Result.ok(bsLawyerResponse);
    }
}
